// Module
module SPREST {

    // Class
    export class Util  {
        static concatenateUrl(pt1: string, pt2: string): string {
            if (pt1 == null || pt2 == null) return null;
            var pt1End: string = pt1[pt1.length - 1];
            var pt2Start: string = pt2[0];
            if (pt1End == '/' && pt2Start == '/') {
                return pt1 + pt2.substring(1);
            }
            else if (pt1End != '/' && pt2Start != '/') {
                return pt1 + '/' + pt2;
            }
            else {
                return pt1 + pt2;
            }
        }

        static getHostOnly(fullUrl: string): string {
            var slashPos: number = 0;

            slashPos = fullUrl.indexOf('/');
            if (slashPos > 0) {
                // 2nd from protocol
                slashPos = fullUrl.indexOf('/', slashPos + 1);
                if (slashPos > 0) {
                    // 3rd (after hostname)
                    slashPos = fullUrl.indexOf('/', slashPos + 1);
                    if (slashPos == 0) { // No trailing slash
                        slashPos = fullUrl.length;
                    }
                }
            }
            return (fullUrl.substring(0, slashPos));
        }
    }

}
